package com.voice.server.service.impl;

import com.voice.server.entity.AppToken;
import com.voice.server.observer.impl.ApiObserver;
import com.voice.server.repository.AppTokenRepository;
import com.voice.server.service.AppTokenService;
import com.wangjiacai.hqlQuery.service.impl.BaseServiceImpl;
import com.wangjiacai.utils.web.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.Executor;

/*
 * @auther: wangjiacai
 *
 * @create: 2019-01-27 18:09:41
 */
@Service
public class AppTokenServiceImpl extends BaseServiceImpl implements AppTokenService {

    @Autowired
    private AppTokenRepository appTokenRepository;
    @Autowired
    private Executor executor;
    @Autowired
    private RedisService redisService;

    @Override
    public AppToken findByUserId(String userId) {
        return appTokenRepository.findByUserId(userId);
    }

    @Override
    public void updatePushUrl(String userId, String pushUrl) {
        AppToken appToken=appTokenRepository.findByUserId(userId);
        appToken.setPushUrl(pushUrl);
        appTokenRepository.save(appToken);
        redisService.hashSet(ApiObserver.hashKey,userId,appToken);
    }

    @Override
    public AppToken findByAppKey(String appKey) {
        return appTokenRepository.findByAppKey(appKey);
    }
}
